package github.ziwukun.jsonql.lang;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

public class SortBuilder implements Serializable{
	private static final long serialVersionUID = -926885490687189492L;
	List<PropSort> propSorts = new LinkedList<>();
	SortBuilder(){}
	
	public SortBuilder asc(String prop) {
		propSorts.add(new PropSortImpl(prop,SortSym.ASC));
		return this;
	}
	
	public SortBuilder desc(String prop) {
		propSorts.add(new PropSortImpl(prop,SortSym.DESC));
		return this;
	}
	
	public SortBuilder prop(String prop,Consumer<SortBuilder> consumer) {
		SortBuilder subBuilder = new SortBuilder();
		consumer.accept(subBuilder);
		
		this.propSorts.add(new PropSortImpl(prop,subBuilder.build()));
		return this;
	}
	
	public Sort build() {
		return new SortImpl(propSorts);
	}
}
